﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.CMS.MODEL;
using Jxym.DBUtility;

namespace Jxym.wlkc2011
{
    public partial class InfoBox : System.Web.UI.UserControl
    {
        public int index = 0;
        private string siteName;
        private string classTitle;
        private int classId = 0;
        private int topN = 10;
        private bool _more = true;
        private int _height = 0;
        private bool _pager = false;
        private bool _newWindow = false;

        public bool NewWindow
        {
            get { return _newWindow; }
            set { _newWindow = value; }
        }

        public bool Pager
        {
            get { return _pager; }
            set { _pager = value; }
        }

        public int Height
        {
            get { return _height; }
            set { _height = value; }
        }

        public bool More
        {
            get { return _more; }
            set { _more = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["siteName"] != null)
                {
                    siteName = Request.Params["siteName"];

                    if (_newWindow)
                    {
                        more.Target = "_blank";
                    }

                    more.Visible = _more;

                    if (_height > 0)
                    {
                        ullist.Style.Add("height", _height + "px");
                    }

                    BinData();
                }
            }
        }

        private void BinData()
        {
            MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();

            Cms_ContentClass cccInfo = ccc.GetModel("siteName='" + siteName + "' AND Title='" + classTitle + "'", null);

            if (cccInfo != null)
            {
                classId = cccInfo.ID;

                more.HRef = SiteName + "_m" + ClassId + ".xhtml";

                if (_pager)
                {
                    AspNetPager1.Visible = true;
                    PagerBinData();
                }
                else
                {
                    AspNetPager1.Visible = false;
                    IList<Cms_Content> list = cct.GetList("ContentClassID=" + classId, null, "AddTime DESC", topN);
                    Repeater1.DataSource = list;
                    Repeater1.DataBind();
                }
            }
        }

        MsSqlDal<Cms_Content> cct = new MsSqlDal<Cms_Content>();

        private void PagerBinData()
        {
            AspNetPager1.RecordCount = cct.GetPageCount("ContentClassID=" + classId, null);
            IList<Cms_Content> list = cct.GetPageList("ContentClassID=" + classId, null, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize);
            Repeater1.DataSource = list;
            Repeater1.DataBind();
        }


        public string SiteName { get { return siteName; } set { siteName = value; } }
        public string ClassTitle { get { return classTitle; } set { classTitle = value; } }
        public int TopN { get { return topN; } set { topN = value; } }
        public int ClassId { get { return classId; } set { classId = value; } }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BinData();
        }
    }
}